package com.yuelao.controller.demo;

import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * swagger演示
 *
 * @author FLY
 * @version v1.0
 * @project yuelao-server
 * @date 2017/8/29 14:13
 * @修改记录 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 */
@Slf4j
@Controller
@RequestMapping(value = "yuelao/{version}")
@ResponseBody
@Api(value = "demo", description = "swagger演示")
public class DemoController {
    @RequestMapping(method = RequestMethod.GET, value = "demo1")
    @ApiOperation(value = "一个参数返回实体", notes = "描述信息", response = DemoInfo.class)
    @ApiImplicitParam(paramType = "query", name = "uid", value = "用户ID", required = true, dataType = "Long")
    public DemoInfo demo1(@RequestParam("uid") Long uid) {
        System.out.println(uid);
        DemoInfo demoInfo = new DemoInfo();
        demoInfo.setId(1L);
        demoInfo.setInfo("feng");
        return demoInfo;

    }


    @RequestMapping(method = RequestMethod.GET, value = "demo2")
    @ApiOperation(value = "多参数加分页演示", notes = "分页返回用户积分变化信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "uid", value = "用户ID", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页记录数", defaultValue = "20", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "page", value = "页数", defaultValue = "1", dataType = "Integer")
    })
    public String demo2(@RequestParam Long uid,
                        @RequestParam Integer pageSize,
                        @RequestParam Integer page) {
        // 分页时从数据库查数据
        //List<CreditChange> creditChangeList = creditService.creditChangesByUid(uid);
        //PageHelper.startPage(page, pageSize);
        // PageInfo pageInfo = new PageInfo<>(creditChangeList);
        // return pageInfo;
        return "success";
    }

    @RequestMapping(method = RequestMethod.GET, value = "demo3")
    @ApiOperation(value = "演示实体参数", notes = "描述信息")
    public String demo3(@RequestBody @ApiParam(name = "用户实体", value = "json格式") DemoInfo demoInfo) {
        System.out.println(demoInfo.getId() + "***" + demoInfo.getInfo());
        return "success";
    }

    @RequestMapping(method = RequestMethod.GET, value = "demo4")
    @ApiOperation(value = "获取url变量", notes = "描述信息")
    public String demo4(@PathVariable Integer version) {
        System.out.println(version);
        return "success";
    }
}
